<template>
  <div>
    <div class="login-body">
      <!-- 登陆框div -->
      <div class="login-container">
        <!-- 登陆框头部logo部分 -->
        <div class="head">
          <div class="name">
            <div class="title">Let's Login</div>
            <div class="tips">登录页面</div>
          </div>
        </div>
        <el-form label-position="top" :rules="rules" :model="ruleForm" ref="ruleForm" class="login-form">
          <el-form-item label="账号" prop="username">
            <el-input type="text" v-model="ruleForm.username"></el-input>
          </el-form-item>
          <el-form-item label="密码" prop="password">
            <el-input type="password" v-model="ruleForm.password" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="验证码" prop="code">
            <el-input v-model="ruleForm.code" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item>
            <el-image
                style="width: 100px; height: 100px"
                @click="changeCode"
                :src="codeUrl"></el-image>
          </el-form-item>
          <el-form-item>
            <div style="color: #333">登录表示您已同意<a>《服务条款》</a></div>
            <el-button style="width: 40%" type="primary" @click="register">注册</el-button>
            <el-button style="width: 40%" type="success" @click="login">登录</el-button>
            <el-checkbox v-model="checked" @change="!checked">下次自动登录</el-checkbox>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>

export default {
  name: "LoginView",
  data(){
    return{
      ruleForm: {
        username: '', // 账号
        password: '', // 密码
        uuid:sessionStorage.getItem("uuid")
      },
      rules: {
        username: [{
          required: 'true',
          message: '请输入账号',
          trigger: 'blur'
        }, {
          min: 3,
          max: 10,
          message: '长度在 3 到 10 个字符',
          trigger: 'blur'
        }],
        password: [{
          required: 'true',
          message: '密码不能为空',
          trigger: 'blur'
        }, {
          min: 3,
          max: 10,
          message: '长度在 3 到 10 个字符',
          trigger: 'blur'
        }],code: [{
          required: 'true',
          message: '验证码不能为空',
          trigger: 'blur'
        },]
      },
      checked: true,
      codeUrl:"http://172.20.10.5:8003/api/tb-user/getCode?uuid="+sessionStorage.getItem("uuid")
    }
  },methods:{
    changeCode(){
      this.$router.go(0)
    },
    register(){
      this.$router.push("/register")
    },login(){
      //alert(this.formLabelAlign.uuid)
      this.axios.post("http://172.20.10.5:8003/api/tb-user/login",this.ruleForm).then(res=>{
        if(res.data.msg=='success'){
          localStorage.setItem("token",res.data.token)
          localStorage.setItem("userId",res.data.userId)
          localStorage.setItem("name",res.data.name)
          localStorage.setItem("roleId",res.data.roleId)
          this.$router.push("/menu")
          alert(res.data.roleId)
          this.$message.success("登录成功")
        }
        else{
          this.$message.error(res.data.msg);
        }
      })
    }
  },created() {

  }
}
</script>

<style scoped>
.login-body {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  background-color: rgb(0, 0, 0,0);
  height: 100vh;


 /* width: 100%; !* 设置div的宽度 *!
  height: 100vh; !* 设置div的高度 *!
  background-image: url('/Users/zhaowenting/Pictures/截屏2024-01-15 10.20.27.jpg'); !* 小熊图片的路径 *!
  background-size: cover; !* 背景图片覆盖整个div区域 *!
  background-position: center; !* 背景图片居中显示 *!
  background-repeat: no-repeat; !* 背景图片不重复 *!*/
}

.login-container {


  width: 470px; /* 设置div的宽度 */
  height: 650px; /* 设置div的高度 */
  background-image: url('/Users/zhaowenting/Pictures/WechatIMG1.jpg'); /* 小熊图片的路径 */
  background-size: cover; /* 背景图片覆盖整个div区域 */
  background-position: center; /* 背景图片居中显示 */
  background-repeat: no-repeat; /* 背景图片不重复 */

}

.head {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40px 0 20px 0;
}

.head img {
  width: 100px;
  height: 100px;
  margin-right: 20px;
}

.head .title {
  font-size: 28px;
  color: #1BAEAE;
  font-weight: bold;
}

.head .tips {
  font-size: 12px;
  color: #999;
}

.login-form {
  width: 70%;
  margin: 0 auto;
}

.login-form>>>.el-form--label-top .el-form-item__label {
  padding: 0;
}

.login-form>>>.el-form-item {
  margin-bottom: 0;
}

.el-form-item {
  text-align: left;
}
.logo {
  background-size: cover;
}
</style>